Ext.onReady(function(){ 

Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'under';

var record_start = 0; 

var sm = new Ext.grid.CheckboxSelectionModel();
var cm=new Ext.grid.ColumnModel([ 
sm,
new Ext.grid.RowNumberer({header: "编号",
width:40, 
renderer:function(value,metadata,record,rowIndex){ 
return record_start + 1 + rowIndex; 
} 
}),
{header:'客户代码',dataIndex:'custId',hidden:true},
{header:'客户名称',dataIndex:'custName',width:100,sortable:true},
{header:'客户类型',dataIndex:'custType',width:100,sortable:true,hidden:true},
{header:'行业类型',dataIndex:'industryType',width:100,sortable:true,hidden:true}, 
{header:'违约状态',dataIndex:'defaultSta',width:100 , sortable:true},
{header:'风险暴露分类',dataIndex:'exposureType',width:100 , sortable:true},
{header:'信用评级',dataIndex:'phaseLevel',width:100,sortable:true},
{header:'信用评级生成日期',dataIndex:'phaseDate',width:100, sortable:true  },
{header:'评级到期日',dataIndex:'endDate',width:100,sortable:true,hidden:true},
{header:'初评人',dataIndex:'firstUserId',width:100,sortable:true},
{header:'评级状态',dataIndex:'phaseStat',width:120, sortable:true  }
]); 

var ds = new Ext.data.Store({ 
proxy:new Ext.data.HttpProxy({
url:'rating/listSortedPD.do?flag=0',
method:'POST'
}), 
reader:new Ext.data.JsonReader({ 
totalProperty:'total',  
root:'resultData'},[
{name:'custId', mapping: 'custInfo.custId'}, 
{name:'custName', mapping: 'custInfo.custName'},  
{name:'custType', mapping: 'custInfo.custType'},  
{name:'industryType', mapping: 'custInfo.industryType'},
{name:'defaultSta', mapping: 'custInfo.defaultSta'},
{name:'exposureType', mapping: 'custInfo.exposureType'},
{name:'phaseLevel', mapping: 'custPD.phaseLevel'},
{name:'phaseDate', mapping:' custPD.secondDate'},
{name:'endDate',mapping:'custPD.endDate'},
{name:'firstUserId', mapping: 'custPD.firstUserId'},
{name:'phaseStat', mapping: 'custPD.phaseStat'}
]) 
}); 
ds.load({params:{start:0,limit:20}}); 

var conditionStore = new Ext.data.SimpleStore({
   fields : ['id', 'text'],
   data : [['custId', '客户编号'], ['custName', '客户名称']]
});

var grid=new Ext.grid.GridPanel({ 
id:'myCustomers',
renderTo:"indCustomer_list", 
stripeRows:true,//斑马线效果
title:"我的零售客户列表", 
height:500, 
cm:cm,
store: ds, 
loadMask: { msg: "加载中..." }, 
viewConfig: {   
                            forceFit:true   
            },   
            bbar: new Ext.PagingToolbar({   
                pageSize: 20,   
                store: ds,
                displayInfo: true,   
                displayMsg: '第{0} 到 {1} 条数据 共{2}条',   
                emptyMsg: "没有数据" ,
                doLoad : function(start){ 
						 	record_start = start; 
							var o = {}, pn = this.getParams(); 
						    o[pn.start] = start; 
						    o[pn.limit] = this.pageSize; 
							this.store.load({params:o}); 
     			}   
            }),
 tbar: [
 {text:'客户评级信息', handler: listCustPD},
 '-',
 '->',
 {xtype:'combo',
 id:'condition',
 name: 'condition', 
 store: conditionStore,
 fieldLabel: '请选择查询条件',
 valueField : 'id',
 displayField : 'text',
 emptyText : '请选择查询条件',
 triggerAction : 'all',
 editable: false,
 mode:'local',
 width:110
 },'',
 {xtype:'textfield',id:'keyword',width:180},
 {text:'查询',handler:findCustomer},
 '-',
 {text:'清空',handler: callBack}
 ]              
});

function findCustomer(){

var condition = Ext.getCmp('condition').getValue();
var keyword = Ext.getCmp('keyword').getValue();

if(condition == '' || condition == null){
	Ext.Msg.alert('提示', '请选择查询条件！'); 
}
else{

	ds.baseParams={condition:condition, keyword: keyword};
	ds.proxy = new Ext.data.HttpProxy({
					url:'rating/findCustomer.do?flag=0',
					method:'POST'
				}); 
	ds.reader = new Ext.data.JsonReader({ 
						totalProperty:'total',  
						root:'resultData'},[
						{name:'custId', mapping: 'custInfo.custId'}, 
						{name:'custName', mapping: 'custInfo.custName'},  
						{name:'industryType', mapping: 'custInfo.industryType'},
						{name:'defaultSta', mapping: 'custInfo.defaultSta'},
						{name:'exposureType', mapping: 'custInfo.exposureType'},
						{name:'phaseLevel', mapping: 'custPD.phaseLevel'},
						{name:'phaseDate', mapping:' custPD.phaseDate'},
						{name:'endDate', mapping:' custPD.endDate'},
						{name:'firstUserId', mapping: 'custPD.firstUserId'},
						{name:'phaseStat', mapping: 'custPD.phaseStat'}
					]);
					   
	ds.load({params:{start:0,limit:20}});
	record_start = 0;  	
}
}

function callBack(){

Ext.getCmp('condition').clearValue();
Ext.getCmp('keyword').setValue('');
	ds.proxy = new Ext.data.HttpProxy({
					url:'rating/listSortedPD.do',
					method:'POST'
				}); 
	ds.reader = new Ext.data.JsonReader({ 
						totalProperty:'total',  
						root:'resultData'},[
						{name:'custId', mapping: 'custInfo.custId'}, 
						{name:'custName', mapping: 'custInfo.custName'},  
						{name:'industryType', mapping: 'custInfo.industryType'},
						{name:'defaultSta', mapping: 'custInfo.defaultSta'},
						{name:'exposureType', mapping: 'custInfo.exposureType'},
						{name:'phaseLevel', mapping: 'custPD.phaseLevel'},
						{name:'phaseDate', mapping:' custPD.phaseDate'},
						{name:'endDate', mapping:' custPD.endDate'},
						{name:'firstUserId', mapping: 'custPD.firstUserId'},
						{name:'phaseStat', mapping: 'custPD.phaseStat'}
					]);   
	ds.load({params:{start:0,limit:20}});
	record_start = 0;

}

function listCustPD(){
	if (grid.getSelectionModel().getSelections()[0] == undefined) { 
		Ext.Msg.alert("提示", "请选中要操作的项！"); 
	}
	else{
		var selectedCustId = grid.getSelectionModel().getSelections()[0].data.custId;
		window.location.href="rating/showReportHistoryPDList.do?custId="+selectedCustId;
	}
}

function rowdblclickFn(grid, rowIndex, e){//双击事件  
	var row = grid.getStore().getAt(rowIndex); 
	var selectedCustId = row.get("custId");
	window.location.href="rating/showReportHistoryPDList.do?custId="+selectedCustId;  
}   

grid.addListener('rowdblclick',rowdblclickFn);

}); 